import store from '../../store'

const user = {
	state: {
		userToken: uni.getStorageSync('userToken') || '',
		userInfo: uni.getStorageSync('userInfo') || '',
	},
	mutations: {
		SET_userToken: (state, userToken) => {
			state.userToken = userToken
		},
		SET_userInfo: (state, userInfo) => {
			state.userInfo = userInfo
		},
	},
	actions: { //异步操作mutation
		remove_userInfo({
			commit
		}, userInfo) {
			uni.removeStorageSync('userInfo');
			commit('SET_userInfo', userInfo)
		},
		set_userToken({
			commit
		}, userToken) {
			uni.setStorageSync('userToken', userToken);
			commit('SET_userToken', userToken)
		},
		set_userInfo({
			commit
		}, userInfo) {
			uni.setStorageSync('userInfo', userInfo);
			commit('SET_userInfo', userInfo)
		},
		remove_logout({
			commit
		}, rememberPassword) {
			uni.removeStorageSync('userInfo');
			uni.removeStorageSync('userToken');
			commit('SET_userToken', '')
			commit('SET_userInfo', '')
			uni.reLaunch({
				url: '/pages/user/login/login'
			})
		},
		wangluoanquan({
			commit
		}, rememberPassword) {
			uni.navigateTo({
				url: '/pages/networkSecurity/networkSecurity',
				success: res => {},
				fail: () => {},
				complete: () => {}
			});
		},
	}
}

export default user